const getters = {

	sum: state => {
		var total = 0;
		state.cart.cartItems.forEach((item) => {
			if (item.hasChecked) {
				total += item.price * item.quantity
			}
		})
		return total
	},
	defaultAddress: state => {
		console.log(JSON.stringify(state.address.addresses.find(p => p.isDefault == 'Y')))
		return state.address.addresses.find(p => p.isDefault == 'Y')
	},
	isCartCheckAll: state => {
		var total = 0;
		console.log("isCartCheckAll .....")
		state.cart.cartItems.forEach((item) => {
			if (item.hasChecked) {
				total++
			}
		})
		return (total == state.cart.cartItems.length && state.cart.cartItems.length > 0) ? true : false;
	},
	cartLength: state => {
		var total = 0;
		state.cart.cartItems.forEach((item) => {
			if (item.hasChecked) {
				total++
			}
		})
		return total
	},
	hasLogin: state => {
		return state.user.hasLogin;
	},
	forcedLogin: state => {
		return state.user.forcedLogin;
	},
	userId: state => {
		return state.user.userId
	},
	getFriendById: (state) => (id) => {
		let friend = state.message.messages.find(p => p.fromPartyId = id);
		return friend;
	},
	getChatRecordById: (state) => (id) => {
		let friend = state.message.friends.find(friend => friend.friendId === id)
		return friend === undefined ? undefined : friend.chatRecords
	},
	sendedCount: state => {
		var item = state.message.sendedMsgCount;
		var year = new Date().getFullYear();
		var month = new Date().getMonth();
		var day = new Date().getDate();
		if (item.sendedTime.getFullYear() == year && item.sendedTime.getMonth() == month && item.sendedTime.getDate() == day) {
			return item.count;
		} else {
			return 0;
		}
	}
}

export default getters;
